package operatori;

import Interpretor.Context;

public class Impartit extends Operator {

	public double calcul(double aux1, double aux2) {
		return Calcul(aux1, aux2);
	}

	public static double Calcul(double aux1, double aux2) {
		if (aux2 == 0) {
			System.err.println("error: division by zero");
			System.exit(1);
		}
		return aux1 / aux2;
	}

	public String concatTermeni(String aux1, String aux2) {
		if (aux1.compareTo("0") == 0)
			return "0";

		if (aux2.compareTo("1") == 0)
			return aux1;

		if (aux1.charAt(0) == '-')
			if (aux2.charAt(0) == '-')
				return aux1.substring(1) + "/" + aux2.substring(1);
			else
				return aux1 + "/" + aux2;
		else if (aux2.charAt(0) == '-')
			return "-" + aux1 + "/" + aux2.substring(1);
		else
			return aux1 + "/" + aux2;

	}

	public static String ConcatTermeni(String aux1, String aux2) {
		if (aux1.compareTo("0") == 0)
			return "0";

		if (aux2.compareTo("1") == 0)
			return aux1;

		if (aux1.charAt(0) == '-')
			if (aux2.charAt(0) == '-')
				return aux1.substring(1) + "/" + aux2.substring(1);
			else
				return aux1 + "/" + aux2;
		else if (aux2.charAt(0) == '-')
			return "-" + aux1 + "/" + aux2.substring(1);
		else
			return aux1 + "/" + aux2;

	}
/*
	public double calculDerivata() {
		if ((fStang == null) || (fDrept == null))
			System.exit(1);

		return calcul(Minus.Calcul(Ori.Calcul(fStang.calculDerivata(), fDrept
				.calcul()), Ori
				.Calcul(fStang.calcul(), fDrept.calculDerivata())), Ori.Calcul(
				fDrept.calcul(), fDrept.calcul()));
	}

	public String derivare() {
		if ((fStang == null) || (fDrept == null))
			System.exit(1);

		return concatTermeni("("
				+ Minus.ConcatTermeni(Ori.ConcatTermeni(fStang.derivare(),
						fDrept.toString()), Ori.ConcatTermeni(
						fStang.toString(), fDrept.derivare())) + ")", Ori
				.ConcatTermeni(fDrept.toString(), fDrept.toString()));
	}
	*/
	public void interpret(Context cont) {
		cont.actual(this);
	}
}
